HTMLify
app.js
Views: 14 | Author: huxn-webdev
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | const body = document.body; const imgs = document.querySelectorAll(".img"); const arrowBtns = document.querySelectorAll(".arrow-btn"); let activeImg = 0; function activeImages() { imgs.forEach((img) => { img.classList.remove("active"); img.classList.remove("animateTransition"); }); imgs[activeImg].classList.add("active"); imgs[activeImg].classList.add("animateTransition"); } setImageAsBackground(); function setImageAsBackground() { body.style.backgroundImage = imgs[activeImg].style.backgroundImage; } arrowBtns.forEach((btn) => { btn.addEventListener("click", () => { if (btn.classList == "right-arrow") { activeImg++; if (activeImg > imgs.length - 1) { activeImg = 0; } } else { activeImg--; if (activeImg < 0) { activeImg = imgs.length - 1; } } setImageAsBackground(); activeImages(); }); }); |